<?php

class Api_IndexController extends Zend_Controller_Action
{

    public function init()
    {
    	$option=array(
    			"layout" => "layout",
    			"layoutPath" => APPLICATION_PATH."/layouts/scripts/default"
    	);
    	Zend_Layout::startMvc($option);
    
    	$this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    }
   
    public function indexAction()
    {
    	$getdmban = new Api_Model_GetDmban();
    	$gethanghoa = new Api_Model_GetHangHoa();
    	$getkhuvuc = new Api_Model_GetKhuVuc();
    	$getnhomhanghoa = new Api_Model_GetNhomHangHoa();
    }
    
    
    public function getdmbanAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    	
    	$getdmban = new Api_Model_GetDmban();
    
    	$rsGetDmban = $getdmban->GetAll();
  	 
    	echo json_encode($rsGetDmban);
    }
    
    public function getiddmbanAction()
    {
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    	 
    	$idDmban = $this->_request->getParam("id","-1");
    	 
    	$getdmban = new Api_Model_GetDmban();
    	$getdmban->Id = $idDmban;
    
    	$rsGetDmban = $getdmban->GetById();
    	 
    	echo json_encode($rsGetDmban);
    }
    
    public function getkhuvucAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$getkhuvuc = new Api_Model_GetKhuVuc();
    	
    	$rsGetKhuVuc = $getkhuvuc->GetAll();
    
    	echo json_encode($rsGetKhuVuc);
    }
    
    public function getidkhuvucAction()
    {
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$idKhuvuc = $this->_request->getParam("id","-1");
    
    	$getkhuvuc = new Api_Model_GetKhuVuc();
    	$getkhuvuc->Id = $idKhuvuc;
    
    	$rsGetKhuvuc = $getkhuvuc->GetById();
    
    	echo json_encode($rsGetKhuvuc);
    }
     
    public function gethanghoaAction()
    {
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$gethanghoa = new Api_Model_GetHangHoa();
    
    	$rsGetHangHoa = $gethanghoa->GetAll();
    
    	echo json_encode($rsGetHangHoa);
    }
    
    public function getidhanghoaAction()
    {
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$idHanghoa = $this->_request->getParam("id","-1");
    
    	$gethanghoa = new Api_Model_GetHangHoa();
    	$gethanghoa->Id = $idHanghoa;
    
    	$rsGetHanghoa = $gethanghoa->GetById();
    
    	echo json_encode($rsGetHanghoa);
    }
    
    public function getnhomhanghoaAction()
    {
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$getnhomhanghoa = new Api_Model_GetNhomHangHoa();
    
    	$rsGetNhomHangHoa = $getnhomhanghoa->GetAll();
    
    	echo json_encode($rsGetNhomHangHoa);
    }
    
    public function getidnhomhanghoaAction()
    {
    
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$idNhomhanghoa = $this->_request->getParam("id","-1");
    
    	$getnhomhanghoa = new Api_Model_GetNhomHangHoa();
    	$getnhomhanghoa->Id = $idNhomhanghoa;
    
    	$rsGetNhomhanghoa = $getnhomhanghoa->GetById();
    
    	echo json_encode($rsGetNhomhanghoa);
    }
    
    public function gethanghoatheonhomAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $idnhomhanghoa = $this->_request->getParam("idnhomhanghoa","-1");
        
    	$getnhomhanghoa = new Api_Model_GetNhomHangHoa();
    	$gethanghoa = new Api_Model_GetHangHoa();
    	
    	$rsGetHangHoaTheoNhom = $gethanghoa->GetHangHoaTheoNhom($idnhomhanghoa);
    	
    	 
    	echo json_encode($rsGetHangHoaTheoNhom);	 
    }
    
    public function LuuAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
    	echo "";
    }
    
    
    //////////////////////////////////////////////////////////////////////////////////////////////
    // Thuan track
    public function luutamAction()
    {
        $this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
        
    	$idBan = $this->_request->getParam("idBan","-1");
    	$idMon = $this->_request->getParam("idMon","-1");
    	$soluong = $this->_request->getParam("soluong","-1");
    	
    	$obLuutam = new Api_Model_Luutam();
    	$obLuutam->Ngaydatmon = date('Y-m-d H:i:s');
    	$obLuutam->IdBan = $idBan;
    	$obLuutam->IdMon = $idMon;
    	$obLuutam->Soluong = $soluong;
    	$obLuutam->Trangthai = "chuathanhtoan";
    	$obLuutam->TrangthaiOrder = "chuaxacnhan";
    	echo json_encode( $obLuutam->Save() );
    	echo("");
    	
    }
    
    public function updatetrangthaiorderAction()
    {        
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);   
       
    	$Id = $this->_request->getParam("Id","(0)");
    	$lstId = $this->_request->getParam("lstId","(0)");
    	$kiemtra = $this->_request->getParam("kiemtra","(0)");
    	 
    	$obLuutam = new Api_Model_Luutam();    	
    	echo json_encode( $obLuutam->UpdateTrangthaiOrder($lstId,$kiemtra,$Id) );       	
    	 
    }
    
    public function getmontheobanAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
       	$idBan = $this->_request->getParam("idBan","-1");
        $obLuutam = new Api_Model_Luutam();
        $obLuutam->Ngaydatmon = date('Y-m-d 00:00:00');
        
        $obLuutam->IdBan = $idBan;
        
        echo json_encode($obLuutam->getDsmontheoban());        
    }
    
    
    public function deletorderbyidAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $idorder = $this->_request->getParam("idorder","-1");
        $obLuutam = new Api_Model_Luutam();
        $obLuutam->Id = $idorder;
        $obLuutam->deleteOderById();
    }
    
    public function cancelorderAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$idBan = $this->_request->getParam("idBan","-1");
    	$obLuutam = new Api_Model_Luutam();    	
    	$obLuutam->cancelOder($idBan);
    }

    
    public function getdsbanactiveAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $obLuutam = new Api_Model_Luutam();
        echo json_encode($obLuutam->getdsbanactive());
    }
    
 	public function chuyenbanAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $idBan = $this->_request->getParam("idBan","-1");      
        $lstIdban = $this->_request->getParam("lstIdban","(0)");
        
       	$obluutam = new Api_Model_Luutam();
       	$obluutam->IdBan = $idBan;
             
       	//echo $lstIdban;
        
        echo json_encode($obluutam->chuyenban($lstIdban));
    }
}



